﻿CREATE PROCEDURE [dbo].[proc_Customer_Apply_Create]
	(
		@CustomerName nvarchar(50),
		@UserName nvarchar(50)
	)
AS
	Begin
		Declare @DepartmentId int,@CustomerId uniqueidentifier
		Select @DepartmentId=DepartmentId From Employee Where UserName=@UserName
		Set @CustomerId = (Select Top 1 CustomerId From Customer Where CustomerName=@CustomerName)
		--插入客户申请表
		Insert Into Customer_Apply(CustomerId,CustomerName,DepartmentId,UserName,CreateDate) Values(@CustomerId,@CustomerName,@DepartmentId,@UserName,GetDate())
		--更新客户表
		Update Customer Set ProtectId=2,ProtectName=@UserName,ProtectDate=Getdate() Where CustomerId=@CustomerId
	End
	RETURN
